#include<stdio.h>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1e5+7;
typedef struct experiment{
	ll ai;
	ll bi;
}Exp;
Exp e[N];
ll ans,sum;
bool cmp(Exp a,Exp b){
	return (double)a.bi/a.ai > (double)b.bi/b.ai;
}
int main(){
	int n,i;
	scanf("%d",&n);getchar();
	for(i=0;i<n;i++){
		scanf("%lld%lld",&e[i].ai,&e[i].bi);
		sum+=e[i].bi;
	}
	sort(e,e+n,cmp);
	for(i=0;i<n-1;i++){
		sum-=e[i].bi;
		ans+=e[i].ai*sum;
	}
	printf("%lld\n",ans);
}
